package io.github.maojian.temp;

/**
 * @Auther: jian.mao
 * @Date: 2022-07-06 09:59
 * @Description:
 */
public class StringDecoder {
    /**
     * 查找并返回解码字符串中的第 K 个字母，本方法按照竞赛题目要求完成
     * @param s 给定的编码字符串
     * @param k 解码字符串中的字母索引
     * @return 找到的第k个字母
     */
    public String decodeAtIndex(String s, int k) {
        int length = s.length();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            if (Character.isLetter(s.charAt(i))) {
                stringBuilder.append(s.charAt(i));
            } else {
                stringBuilder.append(stringBuilder);
            }
        }
        return String.valueOf(stringBuilder.charAt(k-1));
    }

    public static void main(String[] args) {
        String s = "north2king2";
        int k = 16;
        StringDecoder solution = new StringDecoder();
        System.out.println(solution.decodeAtIndex(s, k));
    }
}
